package com.xframe.domain.sys;

import com.xframe.domain.BaseModel;
import com.xframe.xdal.core.DataBaseAccess;
import com.xframe.xdal.core.annotation.AutoFill;
import com.xframe.xdal.core.annotation.XColumn;
import com.xframe.xdal.core.annotation.XSelectItem;
import com.xframe.xdal.core.annotation.XTable;
import com.xframe.xdal.core.constant.AutoFillType;
import com.xframe.xdal.core.model.AKQueryModel;
import com.xframe.xdal.core.model.ConditionValue;
import com.xframe.xdal.core.model.FindOptions;
import lombok.Data;

import java.util.List;

/**
 * 模式模型存储库信息表
 *
 * @author xufeng
 * @version 1.0
 * @date 2023-03-28
 */
@Data
@XTable(value = "sys_model_repository", label = "模式模型存储库信息表")
@XSelectItem(keyName = "repositoryId",codeName = "className",textName = "remark")
public class SysModelBaseRepository extends BaseModel {

    /**
     * 主键
     */
    @AutoFill(AutoFillType.Snowflake)
    @XColumn(name = "REPOSITORY_ID", primaryKeyFlag = true,desc = "主键")
    private Long repositoryId;

    /**
     * 模型ID
     */
    @XColumn(name = "MODEL_ID",uniqueFlag = true,desc = "模型ID")
    private Long modelId;

    /**
     * 模型CODE
     */
    @XColumn(name = "MODEL_CODE",desc = "模型CODE",length = 20)
    private String modelCode;
    /**
     * 存储库类名称
     */
    @XColumn(length = 200,desc = "存储库类名称")
    private String className;


    /**
     * 附加参数
     */
    @XColumn(length = 500,desc = "附加参数",nullFlag = true)
    private String args;

    /**
     * 备注
     */
    @XColumn(nullFlag = true,length = 500,desc = "备注")
    private String remark;


    public static SysModelBaseRepository getInstance(Long modelId){
        SysModelBaseRepository sysModelBaseRepository = DataBaseAccess.getInstance().findByAk(AKQueryModel.valueOf(SysModelBaseRepository.class,modelId));
        return sysModelBaseRepository;
    }


    public static SysModelBaseRepository getInstance(String modelCode){
        FindOptions findOptions = FindOptions.defFindAllOptions();
        findOptions.getConditionValueCollection().add(new ConditionValue("modelCode",modelCode));
        List<SysModelBaseRepository> sysModelRepositories = DataBaseAccess.getInstance().findAll(SysModelBaseRepository.class,findOptions);
        if(sysModelRepositories.size() > 0){
            return sysModelRepositories.get(0);
        }
        return null;
    }


}
